<?php

namespace app\common\validate;

use think\Validate;

class ResourceValidate extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...].
     *
     * @var array
     */
    protected $rule = [
        'code|资源标识' => 'require',
        'name|资源组名称' => 'require|min:2',
        'sort|排序' => 'require|number|gt:0',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'.
     *
     * @var array
     */
    protected $message = [];
    protected $scene = [
        'setResourceStatus' => ['code'],
        'saveResourceGaroupAdd' => ['name', 'sort'],
    ];

    // edit 验证场景定义
    public function sceneLogin()
    {
        return $this->only(['account', 'password'])
              ->remove('account', 'unique');
    }

    public function sceneSaveInfo()
    {
        return $this->only(['name', 'email', 'mobile'])
              ->remove('mobile', 'unique');
    }
}
